const stage = document.querySelector(".stage");
const modalControl = new bootstrap.Modal(modal);
const setForm = (task_id, start_time, end_time, status) => {
  document.querySelector('[name="task_id"]').value = task_id;
  document.querySelector('[name="start_time"]').value = start_time;
  document.querySelector('[name="end_time"]').value = end_time;
  document.querySelector('[name="status"]').value = status;
};
let selected = null;
axios({
  method: "get",
  url: "http://m10.ctymc.cn:24048/Task",
}).then((res) => {
  console.log(res.data);
  const list = res.data;
  let str = "";
  for (let i = 0; i < list.length; i++) {
    str += `<div>
    <ul>
      <li>${list[i].task_id}</li>
      <li class="box box333">+</li>
      <li>部门经理</li>
      <li>
        <input
          type="date"
          class="start_time"
          name=""
          id="datetime"
          value=${list[i].start_time}
        />
      </li>
      <li>
        <input
          type="date"
          class="end_time"
          name=""
          id="datetime"
          value=${list[i].end_time}
        />
      </li>
      <li>可行性分析</li>
      <li>${
        list[i].status === 1
          ? "未完成"
          : "" || list[i].status === 2
          ? "已完成"
          : "" || list[i].status === 3
          ? "已延期"
          : ""
      }</li>
      <li class="xiugai">
        <button id="handle">编辑</button> |
        <button>更多</button>
      </li>
    </ul>
  </div>`;
  }

  stage.innerHTML =
    `<div>
    <ul class="stage-top">
      <li>任务阶段</li>
      <li class="box box333">+</li>
      <li>负责人</li>
      <li>计划开始</li>
      <li>计划结束</li>
      <li>前置任务</li>
      <li>状态</li>
      <li>操作</li>
    </ul>
  </div>` + str;
  const handle = document.querySelectorAll("#handle");
  const modal = document.querySelector("#modal");
  const box333 = document.querySelectorAll(".box333");
  box333.forEach(function (el) {
    el.onclick = () => {
      location.href = "./ctb2.html";
    };
  });

  handle.forEach(function (el, i) {
    el.onclick = () => {
      // 按钮点击，打开弹框

      modalControl.show();
      setForm(
        list[i].task_id,
        list[i].start_time,
        list[i].end_time,
        list[i].status === 1
          ? "未完成"
          : "" || list[i].status === 2
          ? "已完成"
          : "" || list[i].status === 3
          ? "已延期"
          : ""
      );
    };
  });

  const dismiss = document.querySelector("#dismiss");
  const submit = document.querySelector("#submit");
  const tongji = document.querySelector("#tongji");
  dismiss.onclick = () => {
    // 按钮点击，关闭
    modalControl.hide();
  };
});

console.log(submit);
submit.onclick = () => {
  location.href = "./ylc.html";
};
tongji.onclick = () => {
  location.href = "./lj第三个页面.html";
};
